<?php
	class ListGalery {
		var $items;		
		var $adds;
		var $title;
		var $errEmpty;
		var $idUl;
		
		function ListGalery($titre='',$errEmpty="Il n'y a encore personne dans cette liste",$idUL=''){
			$this->items = array();
			$this->title = $titre;
			$this->errEmpty = $errEmpty;
			$this->adds = array();
			$this->idUl = 'id="'.$idUL.'"';
		}
		
		function push($element,$additif=''){
			try{
				if($element instanceof GaleryItem){
					$this->items[]=$element;
					$this->adds[count($this->items) - 1] = $additif;
				}else{throw new Exception("ListGalery : un élément n'implemente pas l'interface GaleryItem");}
			}
			catch (Exception $e)
			{
				echo "PHPFoxEngine Error : ".$e->getMessage();
			}
		}
		
		function __toString(){
			$result = ($this->title == '')?'':'<h3>'.$this->title.'</h3>';
			if(count($this->items)>0){
				$i = 0;
				$result .= '<ul '.$this->idUl.'>';
				foreach($this->items as $element){
					$result .= '<li>'.$element->summary().' '.$this->adds[$i].'</li>';
					$i++;
				}
				$result .= '</ul>';
			}
			else
			{
				$result .= '<p class="error">'.$this->errEmpty.'</p>';
			}
			return $result;
		}
		
		function isEmpty(){
			return empty($this->items);
		}
	}

?>